<template>
  <div class="about">
    <!-- 登录 -->
    <div>
      <p>
        用户名：
        <input v-model="name" />
      </p>
      <p>
        密码：
        <input v-model="pass" />
      </p>
      <button @click="login">登录</button>
    </div>
  </div>
</template>
<script>
import {Message} from 'element-ui'
import router from '../router'
export default {
  name: "about",
  data() {
    return {
      name: "mm",
      pass: "8888",
      okToken:null
    };
  },
  beforeCreate: function() { 

          console.log("创建前")            
      

},
  components: {},

  methods: {
    login: function() {
      const _this = this
      
      this.$axios
        .post("./login", {
          name: this.name,
          pass: this.pass
        })
        .then(function(response) {
          //console.log(response);
          if (response.data.state) {
            //alert(response.data.message);
            _this.okToken=response.data.message;
            localStorage.setItem("token",response.data.message);

            _this.setToken();


            Message.success("登陆成功");
            router.push('/');
          } else {
            Message.error(response.data.message);
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    setToken:function(){
      console.log(this.okToken);
      this.$axios.get("/api/setToken", {
                    params: {
                        'token': this.okToken,
                        
                    }
                }).then(function(response) {

                }).catch(function(error) {
                  console.log(error);
                });
    }
  }
};
</script>